package com.skivingcloud.feign.conf;

import jakarta.annotation.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author hushouquan
 */
@Component
public class RestTemplateTokenInterceptor implements ClientHttpRequestInterceptor{
    @Resource
    private CommonFeignPropertiesConfig commonFeignPropertiesConfig;
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException{
        HttpHeaders headers = request.getHeaders();
        headers.add("feignAccessToken", commonFeignPropertiesConfig.getFeignAccessToken());
        // 保证请求继续被执行
        return execution.execute(request, body);
    }
}
